<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Setting extends CI_Controller {
	
	function __construct() {
    parent::__construct();	
		$this->isLogin();	
		$this->load->model('setting_model');
	}
	
	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}

	public function index(){
		$data['main_view']='admin/setting/read';
		$data['hasil']=$this->setting_model->read();
		$this->load->view('admin/template',$data);
	}

	function seo(){
		$data['main_view']='admin/setting/read';
		$data['hasil']=$this->setting_model->seo();
		$this->load->view('admin/template',$data);
	}

	function pesan(){
		$data['main_view']='admin/setting/read';
		$data['hasil']=$this->setting_model->pesan();
		$this->load->view('admin/template',$data);
	}

	function pertemuan(){
		$data['main_view']='admin/setting/setting_pertemuan';
		$data['hasil']=$this->setting_model->edit('4');
		$this->load->view('admin/template',$data);
	}

	function harga(){
		$data['main_view']='admin/setting/setting_harga';
		$data['hasil']=$this->setting_model->edit('5');
		$this->load->view('admin/template',$data);
	}
	
	function edit($id){
		$data['main_view']='admin/setting/edit';
		$data['hasil']=$this->setting_model->edit($id);
		$this->load->view('admin/template',$data);
	}
	
	function update_seo(){
		$id = $this->input->post('id_setting');
		$data = array(
			'konten' => $this->input->post('setting')
		);

		if($query=$this->setting_model->update($id,$data)){
			$this->session->set_flashdata('pesan', 'Data Sukses Ditambah');
			redirect('setting/seo');
		}
	}

	function update_pesan(){
		$id = $this->input->post('id_setting');
		$data = array(
			'konten' => $this->input->post('setting')
		);

		if($query=$this->setting_model->update($id,$data)){
			$this->session->set_flashdata('pesan', 'Data Sukses Ditambah');
			redirect('setting/pesan');
		}
	}

	function update_harga(){
		$id = $this->input->post('id_setting');
		$data = array(
			'konten' => $this->input->post('harga')
		);

		if($query=$this->setting_model->update($id,$data)){
			$this->session->set_flashdata('pesan', 'Harga telah diubah.');
			redirect('setting/harga');
		}
	}

	function update_pertemuan(){
		$id = $this->input->post('id_setting');
		$data = array(
			'konten' => $this->input->post('pertemuan')
		);

		if($query=$this->setting_model->update($id,$data)){
			$this->session->set_flashdata('pesan', 'Jumlah pertemuan telah diubah.');
			redirect('setting/pertemuan');
		}
	}
}